package ru.jetsoft.reg112.desktop.data;

import java.util.Collection;
import java.util.LinkedList;
import ru.jetsoft.reg112.desktop.BaseException;

public class DataSupplyManager {

    private DataSupply dataSupply;

    public DataSupply newDataSupply() throws BaseException {
        dataSupply = new DataSupply();
        return dataSupply;
    }

    public DataSupply loadDataSupply(String filename) throws BaseException {
        dataSupply = new DataSupply(filename);
        return dataSupply;
    }

    public DataSupply getDataSupply() {
        return dataSupply;
    }

    public static Collection<ParamData> generateData() {
        return generateByParams(ParamCache.getRootParams());
    }

    public static Collection<ParamData> generateByParams(Collection<Param> params) {
        Collection<ParamData> tier = new LinkedList<>();
        ParamData paramData;
        for(Param param: params) {
            paramData = generateParamData(param);
            tier.add(paramData);
        }
        return tier;
    }

    private static ParamData generateParamData(Param param) {
        ParamData paramData = new ParamData(param);
        if(!param.isMultiple()) {
            paramData.setValue(param.getDefaultValue());
        }
        paramData.addChilds(generateByParams(param.getChilds()));
        return paramData;
    }

    public static Collection<ParamData> load(String filename) throws BaseException {
        Collection<ParamData> data = new LinkedList<>();
        return data;
    }
}
